import 'package:flutter/cupertino.dart' show CupertinoSwitch;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:jet_rails/jr_app/jr_views/jr_user/jr_user_controller.dart';
import 'package:jet_rails/jr_app/jr_widgets/jr_app_bar.dart';
import 'package:jet_rails/jr_app/jr_widgets/jr_buttons.dart';
import 'package:jet_rails/jr_app/jr_widgets/jr_common_tile.dart';
import 'package:jet_rails/jr_app/jr_widgets/jr_scaffold.dart';
import 'package:jet_rails/jr_services/jr_services.dart';
import 'package:jet_rails/jr_utils/jr_toast.dart';

class JrSettingView extends StatefulWidget {
  const JrSettingView({Key? key}) : super(key: key);

  @override
  State<JrSettingView> createState() => _JrSettingViewState();
}

class _JrSettingViewState extends State<JrSettingView> {
  final controller = Get.find<JrUserController>();
  @override
  Widget build(BuildContext context) {
    return JrScaffold(
        appBar: JrAppBar(
          title: 'Setting',
        ),
        body: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
          child: Column(
            children: [
              JrCommonTile(
                content: Text('ID: ${JrServices.instance.loginUser.value.userId ?? ''}',
                    style: TextStyle(fontSize: 16.sp, color: Colors.white)),
                onTap: () {
                  Clipboard.setData(ClipboardData(text: JrServices.instance.loginUser.value.userId ?? ''));
                  JrToast.show('Copied');
                },
              ),
              SizedBox(height: 16.h),
              Obx(() => JrCommonTile(
                    content: Row(
                      children: [
                        Text('Auto translate', style: TextStyle(fontSize: 16.sp, color: Colors.white)),
                        const Spacer(),
                        CupertinoSwitch(
                            value: controller.autoTranslation.value,
                            onChanged: (_) {
                              controller.toggleAutoTranslation();
                            },
                            activeColor: const Color(0xFF8A6DFF))
                      ],
                    ),
                    onTap: () {},
                  )),
              const Spacer(),
              JrGradientButton(
                text: 'Logout',
                onTap: () {
                  JrServices.instance.logout();
                },
              ),
              SizedBox(height: 16.h),
              GestureDetector(
                onTap: () {
                  Get.dialog(
                      Center(
                        child: Container(
                          height: 200.h,
                          width: 320.w,
                          padding: EdgeInsets.symmetric(horizontal: 24.h, vertical: 32.w),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(10.r),
                              image: const DecorationImage(
                                  alignment: Alignment.bottomCenter,
                                  image: AssetImage('assets/webp/img_activity_widget_bg.webp'),
                                  fit: BoxFit.fitWidth)),
                          child: Column(
                            children: [
                              const Text(
                                'Are you sure you want to delete the account?',
                                style: TextStyle(color: Colors.white),
                              ),
                              SizedBox(height: 24.h),
                              JrGradientButton(
                                  height: 40.h,
                                  width: 200.w,
                                  text: 'Yes',
                                  onTap: () {
                                    JrServices.instance.deleteAccount();
                                    Get.back();
                                  }),
                              SizedBox(height: 10.h),
                              JrGradientButton(
                                height: 40.h,
                                width: 200.w,
                                text: 'Return',
                                onTap: Get.back,
                                gradient: const LinearGradient(colors: [Colors.black38, Colors.black38]),
                              )
                            ],
                          ),
                        ),
                      ),
                      transitionDuration: const Duration(milliseconds: 100));
                },
                child: const Text(
                  'Delete account',
                  style: TextStyle(
                    color: Color(0xFFFF56BB),
                    decoration: TextDecoration.underline,
                  ),
                ),
              ),
              SizedBox(height: 100.h),
            ],
          ),
        ));
  }
}
